<template>
  <a-dropdown :disabled="exportTemplateData.length<=0">
    <a-button class="export" shape="circle" icon="download" :title="exportTemplateData.length<=0?'未查询到导出模板':''" ></a-button>
    <a-menu slot="overlay">
      <template v-for="(item,i) in exportTemplateData">
        <a-menu-item :key="i">
          <a @click="handleClick(item)" href="javascript:;">{{item.fileName}}</a>
        </a-menu-item>
      </template>
    </a-menu>
  </a-dropdown>
</template>

<script>
import { getAction } from '@/services/manage'
import Criteria from '@/utils/criteria'
import { OPERATOR } from '@/store/mutation-types'
export default {
  name: 'VxeToolbarExport',
  props: {
    renderOptions: Object,
    params: Object,
    toolbarProps: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      exportTemplateData: [],
      url: {
        list: '/excel/export/solution/page'
      }
    }
  },
  methods: {
    handleClick(item) {
      const { events = {}} = this.renderOptions
      // const { button, $grid } = this.params
      events.click && events.click(item.code, item.fileName)
    },
    loadExportTemplateData(arg) {
      var params = this.getQueryParams()// 查询条件
      return getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.exportTemplateData = res.result.content
        }
      })
    },
    getQueryParams() { // 获取查询条件
      const queryParam = new Criteria()
      queryParam.addCriterions({ elementId: this.toolbarProps.elementId }, OPERATOR.EQ)// 过滤参数转换为jpa支持格式
      var param = Object.assign({}, { criteria: queryParam.getEncode() })
      param.pageNo = 1
      param.pageSize = 20 // 只展示20条
      return param
    }
  },
  mounted() {
    this.loadExportTemplateData()
  }

}
</script>
<style lang="less" >
.z-vxe-toolbar{
  .export{
    height:30px;
    width:30px;
    i{
      font-size: 14px;
      line-height: 30px;
    }
  }
  .ant-btn-circle{
    min-width:30px;
  }
}
</style>
